<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .active {
            color: aquamarine;
            text-decoration: line-through;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <info-title @getinfo="pushinfo"></info-title>
        <div v-for="(item,index) in infoList">
            <span :class="item.status ? 'active' : '' ">{{item.message}}</span>
            <button v-if="item.status" @click="changeStatus(index)">已完成</button>
            <button v-else @click="changeStatus(index)">未完成</button>
            <button @click="del(index)">删除</button>
        </div>
    </div>

    <!-- 子组件 -->
    <template id="title">
        <div>
            <input type="text" v-model="str"> <button @click="addinfo"> add </button>
        </div>
    </template>
</body>
<script>

    Vue.component('infoTitle', {
        template: '#title',
        data() {
            return {
                str: '',
            }
        },
        methods: {
            addinfo() {
                if (this.str) {
                    this.$emit('getinfo', this.str)
                    this.str = ''
                }
            }
        }
    })


    new Vue({
        el: '#wrap',
        data: {
            infoList: [{ message: '开始今天的计划咯', status: false }]
        },
        methods: {
            pushinfo(val) {
                this.infoList.push({ message: val, status: false })
            },
            changeStatus(i) {
                this.infoList[i].status = !this.infoList[i].status
            },
            del(i) {
                this.infoList.splice(i, 1)
            }
        }
    })





</script>

</html>